import pickle
import random
import threading
import time
import tkinter as tk  # 使用Tkinter前需要先导入
import tkinter.messagebox  # 要使用messagebox先要导入模块
import requests


class Blog:
    userAgent = ['my-app/0.0.1',
                 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1',
                 'Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50',
                 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0']

    # 获取随机user-agent
    def randomUserAgent(self):
        i = random.randint(0, len(self.userAgent) - 1)
        return self.userAgent[i];

    # 增加浏览量
    def cheatCount(self, articles):
        tkinter.messagebox.showinfo(title='启动信息', message='刷博客流量程序已启动,确认后请将程序挂在一旁,暂时不要点击其他按钮！')
        headers = {
            'user-agent': self.randomUserAgent()
        }
        while True:
            for j in range(len(articles)):
                res = requests.get(articles[j], headers=headers)
                time.sleep(random.randint(2, 5))
                print(res.text + '第{}篇'.format(j))

    # 写URL
    def writeWord(self, data):
        f = open("data.txt", "wb")
        pickle.dump(data, f, True);
        f.close()

    # 读URL
    def readWord(self):
        f = open("data.txt", "rb")
        data = pickle.load(f)
        f.close()
        return data;



def __init__(self):
    print('blog对象已构建')


if __name__ == '__main__':
    blog = Blog();
    print(blog.readWord())
